ROOT_PATH:=${PWD}/..
THIRD_PATY_LIBS_PATH:=$(ROOT_PATH)/thirdParty/libs/linux
OUTPUT:=${ROOT_PATH}/output
DEMO:=${ROOT_PATH}/demo
DATA:=${ROOT_PATH}/data
ENABLE_RAW ?= no
ENABLE_GAMMA ?= no

cc:=g++
ccflag:=-w -O3 -fpermissive -pthread -luvc -lusb-1.0 -L$(THIRD_PATY_LIBS_PATH)/. -I$(THIRD_PATY_LIBS_PATH)/ -lGL -lGLU -lglut -w -O3
ccflag_cv:= -lm `pkg-config --cflags --libs opencv`

src:=${ROOT_PATH}/driver/src/*.c
include:=${ROOT_PATH}/driver/include/

src_demo:=${DEMO}/uvcDemo.c
src_demo+=${src}

src_demo_gl:=${DEMO}/uvcDemoGL.c
src_demo_gl+=${src}

src_demo_bmp:=${DEMO}/bmpDemo.c
src_demo_bmp+=${src}

src_demo_showGL:=${DEMO}/showGLDemo.c
src_demo_showGL+=${src}

src_demo_hist:=${DEMO}/histDemo.c
src_demo_hist+=${src}

exe_demo:=${OUTPUT}/uvcDemo
exe_demoGL:=${OUTPUT}/uvcDemoGL
exe_demoBMP:=${OUTPUT}/bmpDemo
exe_demoSHOWGL:=${OUTPUT}/showGLDemo
exe_demoHIST:=${OUTPUT}/histDemo

ifeq ($(strip $(ENABLE_RAW)), yes)
# ifeq ($(ENABLE_RAW), yes)
DEFINES += -DENABLE_RAW=$(ENABLE_RAW)
endif

ifeq ($(strip $(ENABLE_GAMMA)), yes)
# ifeq ($(ENABLE_GAMMA), yes)
DEFINES += -DENABLE_GAMMA=$(ENABLE_GAMMA)
endif

build:
		mkdir -p ${OUTPUT}
		$(cc) $(src_demo) $(ccflag) ${ccflag_cv} ${DEFINES} -I${include} -o $(exe_demo)
		$(cc) $(src_demo_gl) $(ccflag) -I${include} -o $(exe_demoGL)
		$(cc) $(src_demo_bmp) $(ccflag) -I${include} -o $(exe_demoBMP)
		$(cc) $(src_demo_showGL) $(ccflag) -I${include} -o $(exe_demoSHOWGL)
		$(cc) $(src_demo_hist) $(ccflag) -I${include} -o $(exe_demoHIST)
clean:
		rm -rf ${OUTPUT}
run:
		$(exe_demo)
run_gl:
		$(exe_demoGL)
run_bmp:
		mkdir -p ${OUTPUT}/bmp
		${exe_demoBMP} ${DATA}/lena.bmp
run_showGL:
		${exe_demoSHOWGL} ${DATA}/lena.bmp
run_hist:
		mkdir -p ${OUTPUT}/hist
		${exe_demoHIST} ${DATA}/lena.bmp